import scrapy
from scrapy.selector import Selector
import sys
import json
import codecs
import time
import datetime
import os
import urllib

reload(sys)
sys.setdefaultencoding('utf-8')

class jiujiuSpider(scrapy.Spider):
    path= os.getcwd()+u"\\DataFolder\\MTX\\"
    def __init__(self):
        if(not(os.path.exists(self.path))):
            os.makedirs(self.path,0755) #create the folder
        of =codecs.open(self.path+time.strftime("%Y-%m-%d",time.localtime())+"_jiujiu.json","wb",encoding="utf-8")
        of.close()

    name ="jiujiu"
    allowed_domains="baidu.com"
    start_urls=["https://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fr=&hs=0&xthttps=111111&sf=1&fmq=&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&word=%E9%A3%8E%E6%99%AF"]
    custom_settings = {'ITEM_PIPELINES':{'tutorial.pipelines.SJiuJiuPipeline':500,}}

    def parse(self,response):
        strdata =str( response.text.encode('utf-8'))
        of =codecs.open(self.path+time.strftime("%Y-%m-%d",time.localtime())+"_jiujiu.json","wb",encoding="utf-8")
        of.write(strdata)
        of.close()         
